﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DaliUsbDemo.DaliHelper.MemoryBank
{
    internal static class ControlGearMemoryBank
    {
        private static List<string> cgMemoryBank0LocationDescriptions = new List<string>()
        {
            "last accesible memory location",
            "reserved",
            "last accesible memory bank",
            "GTIN byte 0",
            "GTIN byte 1",
            "GTIN byte 2",
            "GTIN byte 3",
            "GTIN byte 4",
            "GTIN byte 5",
            "firmware version (major)",
            "firmware version (minor)",
            "identification number byte 0",
            "identification number byte 1",
            "identification number byte 2",
            "identification number byte 3",
            "identification number byte 4",
            "identification number byte 5",
            "identification number byte 6",
            "identification number byte 7",
            "hardware version (major)",
            "hardware version (minor)",
            "101 version number",
            "102 version number",
            "103 version number",
            "number of logical control devices",
            "number of logical control gears",
            "index of logical control gear",
            "current bus unit configuration" // new defined in diiasw098bg
        };

        private static List<string> cgMemoryBank1LocationDescriptions = new List<string>()
        {
            "last accessible memory location",
            "indicator byte",
            "memory bank 1 lock byte",
            "OEM GTIN byte 0",
            "OEM GTIN byte 1",
            "OEM GTIN byte 2",
            "OEM GTIN byte 3",
            "OEM GTIN byte 4",
            "OEM GTIN byte 5",
            "OEM identification number byte 0",
            "OEM identification number byte 1",
            "OEM identification number byte 2",
            "OEM identification number byte 3",
            "OEM identification number byte 4",
            "OEM identification number byte 5",
            "OEM identification number byte 6",
            "OEM identification number byte 7"
        };

        public static string GetLocationDescription(int bank, int location)
        {
            if ((bank < 0) || (bank > 255) || (location < 0) || (location > 255))
            {
                throw new ArgumentOutOfRangeException("bank or location value is not valid!");
            }

            switch (bank)
            {
                case 0: 
                    return (location < cgMemoryBank0LocationDescriptions.Count) ? cgMemoryBank0LocationDescriptions[location] : "";
                case 1:
                    return (location < cgMemoryBank1LocationDescriptions.Count) ? cgMemoryBank1LocationDescriptions[location] : "";
                default:
                    return "";
            }
        }
    }
}
